<%extends"admin/base.html"%><%block content%>
<div class="layui-card">
  <div class="layui-card-header layuiadmin-card-header-auto layui-form">
    <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
  </div>
  <div class="layui-card-body">
    <table id="LAY-app-content-tags" lay-filter="LAY-app-content-tags"></table>
    <script type="text/html" id="layuiadmin-app-cont-tagsbar">
      <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </script>
      <script type="text/html" id="buttonTpl">
      <img src="{{ d.imgSrc }}" alt="{{ d.imgName }}"/>
    </script>
  </div>
</div>
<%endblock%>
<%block script%>
    var active = {
        add: function(){
        layer.open({
          type: 2
          ,title: '添加相片'
          ,content: "<< url_for('admin.PhotoAdd') >>"
          ,area: ['460px', '500px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
            submit.click();
          }
        });
      }
    }
    $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    table.render({
        elem: "#LAY-app-content-tags",
        url: "<< url_for('admin.PhotoList') >>",
        page: !0,
        limit: 15,
        limits: [10, 15, 20, 25, 30],
        text: {
            none: '暂无相关数据',
            error:'对不起，加载出现异常！'
        },
        method:'post',
        cols: [[{field: "Id", width: 100, title: "Id", sort: !0}, {
            field: "imgName",
            title: "分类名",
            minWidth: 100
        }, {
            field: "createTime",
            title: "发布时间",
            minWidth: 100
        }, {field: "imgSrc", title: "相片", templet: "#buttonTpl", minWidth: 50, align: "center"}, {title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#layuiadmin-app-cont-tagsbar"}]]
    }), table.on("tool(LAY-app-content-tags)", function (t) {
        var i = t.data;
        if ("del" === t.event) layer.confirm("确定删除此相片？", function (e) {
            layer.close(e)
            //执行 Ajax 后重载
          $.ajax({
            url: "<< url_for('admin.PhotoDel') >>",
            data:{Id:i.Id},
            success: function (returnData) {
                if (returnData.status == 1) {
                    table.reload('LAY-app-content-tags');
                    layer.msg('已删除');
                    t.del()
                }
                else {
                    layer.msg(returnData.error);
                }
             }
          });
        }); else if ("edit" === t.event) {
            layer.open({
                type: 2,
                title: "编辑相片",
                content: "/admin/album/edit/" + i.Id,
                area: ["450px", "500px"],
                btn: ["确定", "取消"],
                yes: function (e, i) {
                    var l = window["layui-layer-iframe" + e],
                    a = i.find("iframe").contents().find("#layuiadmin-app-form-edit");
                    a.click();
                }
            })
        }
    });
    $('.layui-nav-item').removeClass('layui-this');
    $('#admin_album_nav').addClass('layui-this');
<%endblock%>